<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="bootoast/bootoast.css">
    <script src="js/jquery-3.6.0.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="bootoast/bootoast.js" type="text/javascript" charset="utf-8"></script>
    <style>

        .container-fluid{
            padding-left: 0px;
            padding-right: 0px;
        }
        .form-group{
            margin-right: 30px auto;
        }
        .btn{
            margin-right: 30px;
        }
    </style>
    <script>
        $(function (){
            //查询当前用户
            $.ajax({
                url:'get_admin_byid',
                type:'post',
                cache:false,
                data:{id:sessionStorage.getItem("adminId")},
                dataType:'json',
                success:function (rst){
                    if (rst.code==1){
                        $('#adminId').val(rst.data.adminId);
                        $('#account').val(rst.data.account);
                        $('#nickName').val(rst.data.nickName);
                    }else {
                        bootoast({
                            message:rst.msg,
                            type:'danger',
                            position:'top',
                            timeout:2
                        });
                    }
                }
            });
            $('#btnEdit').click(function () {
                if ($('#account').val()==''){
                    bootoast({
                        message:'账号不能为空',
                        type:'danger',
                        position:'top',
                        timeout:2
                    });
                    return;
                }
                if ($('#nickName').val()==''){
                    bootoast({
                        message:'昵称不能为空',
                        type:'danger',
                        position:'top',
                        timeout:2
                    });
                    return;
                }
                //修改
                $.ajax({
                    url:'edit_admin',
                    type:'post',
                    cache:false,
                    data:$('#form1').serialize(),
                    dataType:'json',
                    success:function (rst){
                        if (rst.code==1){
                            bootoast({
                                message:rst.msg,
                                type:'success',
                                position:'top',
                                timeout:2
                            });
                        }else {
                            bootoast({
                                message:rst.msg,
                                type:'danger',
                                position:'top',
                                timeout:2
                            });
                        }
                    }
                });
            })
        })

    </script>
</head>

<body>
    <div class="container-fluid">
        <ul class="breadcrumb">
            <li><a href="#">首页</a></li>
            <li><a href="#">个人中心</a></li>
            <li>个人信息</li>
        </ul>
        <div class="row">
            <div class="col-sm-8 col-sm-offset-2">
                <form id="form1">
                    <div class="form-group">
                        <label for="adminId">编号</label>
                        <input type="text" readonly name="adminId" id="adminId" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="account">账号/手机</label>
                        <input type="text" id="account" name="account" class="form-control">
                    </div>
                    <div class="form-group">
                        <label for="nickName">昵称</label>
                        <input type="text" id="nickName" name="nickName" class="form-control">
                    </div>
                    <div class="form-group"> 
                        <input type="button" class="btn btn-primary" id="btnEdit" value="修 改">
                    </div>
                </form>
            </div>
        </div>

    </div>
</body>

</html>